from django.shortcuts import render
import requests
#使用的是apitower.setting里的url
from apitower.setting import *
"""
郭鼎
房间物品查询
提交方式POST
本链接后缀:api_asset_inquire/api_asset_inquire/
提交格式{'tower_name': ['教学楼'],
        'floor_num': ['3'],
        'room_num': ['311'],
        'verify_pswd': '123'}
"""
def api_asset_inquire(request):
    if request.method == "POST":
        info = dict(request.POST)
        info['verify_pswd'] = request.post.get('verify_pswd')
        asset_api = url+"asset/asset_inquire/"
        r = requests.post(asset_api,data=info)
        print(r.json())
        fields = r.json()
        if fields["message"] == '没有这个楼':
            context = fields
            return render(request, "asset_inquire.html", {"field": context})
        elif fields["message"] == '这楼没这层':
            context = fields
            return render(request, "asset_inquire.html", {"field": context})
        elif fields["message"] == '这层没这屋':
            context = fields
            return render(request, "asset_inquire.html", {"field": context})
        else:
            context = fields
            print(context)
            return render(request,"all_materials.html", context)
    elif request.method == "GET":
        fields = {}
        fields[" field "]="请输入您要查询的楼房"
        return render(request, "asset_inquire.html", {'field':"请输入您要查询的楼房"})
